package com.dating.entities;

import java.util.ArrayList;

import android.app.AlertDialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;

import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;

@SuppressWarnings("rawtypes")
public class UserItemizedOverlay extends ItemizedOverlay {

	private ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
	Context mContext;
	
	public UserItemizedOverlay(Drawable defaultMarker,Context context) {
		super(boundCenterBottom(defaultMarker));
		this.mContext=context;
	}

	// Each time you add a new OverlayItem to the ArrayList, you must call
	// populate() for the ItemizedOverlay, which will read each of the
	// OverlayItem objects and prepare them to be drawn.
	public void addOverlay(OverlayItem overlay) {
		mOverlays.add(overlay);
		// When the populate() method executes, it will call createItem(int) in
		// the ItemizedOverlay to retrieve each OverlayItem. You must override
		// this method to properly read from the ArrayList and return the
		// OverlayItem from the position specified by the given integer
		populate();
	}
	
	@Override
	protected OverlayItem createItem(int i) {
	  return mOverlays.get(i);
	}

	@Override
	public int size() {
	  return mOverlays.size();
	}
	
	@Override
	protected boolean onTap(int index) {
	  OverlayItem item = mOverlays.get(index);
	  AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
	  dialog.setTitle(item.getTitle());
	  dialog.setMessage(item.getSnippet()+item.getPoint().getLatitudeE6()+"-"+item.getPoint().getLongitudeE6());
	  dialog.show();
	  return true;
	}
}
